package com.hikvision.cms.common.util;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;


public class MapUtil {
    public static Map<String, Object> Obj2Map(Object obj) throws Exception {
        /* 17 */
        Map<String, Object> map = new HashMap<>();
        /* 18 */
        Field[] fields = obj.getClass().getDeclaredFields();
        /* 19 */
        for (Field field : fields) {
            /* 20 */
            field.setAccessible(true);
            /* 21 */
            map.put(field.getName(), field.get(obj));
        }
        /* 23 */
        return map;
    }


    public static Object map2Obj(Map<String, Object> map, Class<?> clz) throws Exception {
        /* 28 */
        Object obj = clz.newInstance();
        /* 29 */
        Field[] declaredFields = obj.getClass().getDeclaredFields();
        /* 30 */
        for (Field field : declaredFields) {
            /* 31 */
            int mod = field.getModifiers();
            /* 32 */
            if (!Modifier.isStatic(mod) && !Modifier.isFinal(mod)) {


                /* 35 */
                field.setAccessible(true);
                /* 36 */
                field.set(obj, map.get(field.getName()));
            }
            /* 38 */
        }
        return obj;
    }
}

